import { ref } from "vue";
import { ByteView, parse } from "./codec";
import { Cmd, Type, onResp } from "./proto";

export const logs = ref<string[]>([]);


function onRecvNotify(buf: number[]) {
    const cmd = buf[2];

    if (cmd != Cmd.LOG) {
        return;
    }

    const bw = new ByteView();
    parse(buf, bw);
    logs.value.push(bw.toString());
}

export function onRecv(buf: number[]) {
    const type = buf[0];
    if (type == Type.NOTIFY) {
        onRecvNotify(buf);
        return;
    }
    const seq = buf[1];
    onResp(type, seq, buf);
}



